<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%
    Integer uid = token.getUid();
    List<UserProfile> userProfiles = QBuilder.db("basedb").select().from("UserProfile").where(new Where("hospital=", hospital).and("status=", STATUS_ENABLE).and("uid=", uid)).query().getResultObj();
    String uids = "" + uid;
    for (int i = 0; i < userProfiles.size(); i++) {
        UserProfile userProfile = userProfiles.get(i);
        uids += "," + userProfile.getId();
    }
    List<Order> orders = QBuilder.db("basedb").select().from("Order").where(new Where("hospital =", hospital).and("status = ", STATUS_ENABLE).and("uid in ("+ uids +")")).order("registerTime", QBuilder.desc).query().getResultObj();
    if (isEmpty(orders)) {
        msg = new Message(30041, "暂无预约信息");
        Tools.encryptPrint(out, msg);
        return;
    }
    List<Map> waits = new ArrayList<Map>();
    List<Map> deals = new ArrayList<Map>();
    List<Map> overs = new ArrayList<Map>();
    List<Map> cancels = new ArrayList<Map>();
    for (int i = 0; i < orders.size(); i++) {
        Order order = orders.get(i);
        Integer state = order.getState();
        Map map = new HashMap();
        map.put("patient_name", order.getUserName());
        map.put("doctor_name", order.getDoctorName());
        map.put("title", order.getTitle());
        map.put("state", state);
        map.put("register_time", DateUtil.formatDate(new Date(order.getRegisterTime())));
        map.put("exec_time", isEmpty(order.getExecTime()) ? "" : DateUtil.formatDate(new Date(order.getExecTime())));
        map.put("half", order.getHalf());
        map.put("age", order.getAge());
        map.put("type", order.getType());
        map.put("phone", order.getPhone());
        map.put("start_time", order.getStartTime());
        map.put("end_time", order.getEndTime());
        map.put("order_id", order.getId());
        switch (state) {
            case 1:
                waits.add(map);
                break;
            case 2:
                deals.add(map);
                break;
            case 3:
                overs.add(map);
                break;
            case 4:
            case 5:
                cancels.add(map);
                break;
            case 6:
                break;
            default:
                break;
        }
    }
    Map map = new HashMap();
    map.put("waits", waits);
    map.put("deals", deals);
    map.put("overs", overs);
    map.put("cancels", cancels);
    msg.put("data", map);
    Tools.encryptPrint(out, msg);
%>
